package com.qiall.omsserver.service.dubbo.findService;

import com.qiall.datautil.RandomUtil;
import com.qiall.oms.ability.request.FindDubboServiceResponse;
import com.qiall.omsserver.data.entity.DubboServiceInfo;
import com.qiall.omsserver.data.mapper.DubboServiceInfoMappr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 吴金辉
 */
@Component
public class FindDubboServiceImplRandom implements  FindDubboService{

    @Autowired
    private DubboServiceInfoMappr dubboServiceInfoMappr;
    @Override
    public DubboServiceInfo FindDubboServiceByStrategy(String requestService, String group,String version) {
        List<DubboServiceInfo> serviceInfos = dubboServiceInfoMappr.selectByServiceAndGroup(requestService, group,version);
        int random = RandomUtil.getRandomInt(serviceInfos.size());
        DubboServiceInfo serviceInfo = serviceInfos.get(random);
        return serviceInfo;
    }

    @Override
    public StrategyEnum getStrategy() {
        return StrategyEnum.随机获取;
    }


}
